<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <#-- 包含其他文件的内容 -->
    <#include "../common/header.ftl"/>
    <script type="text/javascript" src="/js/ckeditor/ckeditor.js"></script>
    <script>
        $(function () {
            $('.inputBtn').click(function () {
                $('#editForm')[0].reset();//reset不能清空type为hidden的隐藏域,如果type=text,有hidden属性则可以被清空
                $('#coverImg').attr('src', '');
                ck.setData('');
                var json = $(this).data('json');
                if (json) {
                    // console.log(json);
                    $('input[name=id]').val(json.id);
                    $('input[name=title]').val(json.title);
                    $('#coverImg').attr('src', json.coverUrl);
                    $('input[name=coverUrl]').val(json.coverUrl);
                    $('select[name=state]').val(json.state);
                    $('select[name=sequence]').val(json.sequence);
                    $.get('/daily/selectContentById.do',{id:json.id},function (data) {
                        ck.setData(data.content);
                    })
                }
                $('#inputModal').modal('show');

            });
            $('.submitBtn').click(function () {
                var content = ck.getData();//获得文本内容
                $('textarea[name="dailyContent.content"]').html(content);
                $('#editForm').ajaxSubmit(function (data) {
                    handleResult(data);
                })
            });
        })
    </script>
</head>
<body>

<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl"/>
    <div class="row">
        <div class="col-sm-3">
            <#-- 往数据模型中填充一个属性 -->
            <#assign menu="daily"/>
            <#include "../common/menu.ftl"/>
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">日报管理</h1>
                </div>
            </div>
            <!--高级查询--->
            <form class="form-inline" id="searchForm" action="/daily/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <div class="form-group">
                    <label>关键字:</label>
                    <input type="text" class="form-control" name="keyword"
                           value="${(qo.keyword)!}" placeholder="请输入标题">
                </div>
                <button id="btn_query" class="btn btn-success">
                    <span class="glyphicon glyphicon-search"></span> 查询
                </button>
                <a role="button" class="btn btn-success inputBtn">
                    <span class="glyphicon glyphicon-plus"></span> 添加
                </a>
            </form>

            <table class="table table-striped table-hover">
                <tr>
                    <th>编号</th>
                    <th>标题</th>
                    <th>封面</th>
                    <th>创建时间</th>
                    <th>状态</th>
                    <th>发布时间</th>
                    <th>推荐</th>
                    <th>操作</th>
                </tr>

                <#-- 循环迭代指令 -->
                <#list pageInfo.list as entity>
                    <tr>
                        <td>${entity_index+1}</td>
                        <td>${entity.title}</td>
                        <td><img src="${entity.coverUrl}" width="100px"/></td>
                        <td>${entity.createTime?string("yyyy-MM-dd")}</td>
                        <td>${entity.stateName}</td>
                        <td>${(entity.releaseTime?string("yyyy-MM-dd"))!}</td>
                        <td>${entity.sequenceName}</td>
                        <td>
                            <a class="btn btn-info btn-xs inputBtn" data-json='${entity.json}'>
                                <span class="glyphicon glyphicon-pencil"></span> 修改
                            </a>
                        </td>
                    </tr>
                </#list>
            </table>
            <#include "../common/page.ftl"/>
        </div>
    </div>
</div>


<!-- 模态框必须作为body的子标签 -->
<div class="modal fade" id="inputModal" tabindex="-1" role="dialog"
     aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title" id="myModalLabel">新增/编辑</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/daily/saveOrUpdate.do" method="post" id="editForm">
                    <input type="text" name="id" hidden>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="title">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">封面：</label>
                        <div class="col-sm-6">
                            <img id="coverImg" width="100%"/>
                            <input type="text" name="coverUrl" hidden>
                            <input type="file" class="form-control" name="file">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">状态：</label>
                        <div class="col-sm-6">
                            <select class="form-control" name="state">
                                <option value="0">草稿</option>
                                <option value="1">发布</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">热门：</label>
                        <div class="col-sm-6">
                            <select class="form-control" name="sequence">
                                <option value="0">否</option>
                                <option value="1">是</option>
                            </select>
                        </div>
                    </div>
                    <textarea name="dailyContent.content" id="editor1" rows="10" cols="80">
                       添加日报内容......
                    </textarea>
                    <script>
                        // Replace the <textarea id="editor1"> with a CKEditor
                        // instance, using default configuration.
                        var ck = CKEDITOR.replace('editor1');
                    </script>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">
                    <span class="glyphicon glyphicon-off"></span> 关闭
                </button>
                <button type="button" class="btn btn-primary submitBtn">
                    <span class="glyphicon glyphicon-saved"></span> 保存
                </button>
            </div>
        </div>
    </div>
</div>

</body>
</html>